<?php require_once('../../includes/spip_launcher.php'); ?>

        $(document).ready(function() {
        insert_index = 0;
	   $('.list_form .add_field_button').click(function(){
	       var container = $('.list_form .elements_container');
	       var content = '<tr>';
            content += '<td>';
            content += '?';    
            content += '</td>';            
            content += '<td>';
            
            // Inputs for insert here
            content += '<input type="text" name="elements_insert['+insert_index+'][titre]" value="" style="width: 400px;" />';
            content += '<input type="hidden" name="elements_insert['+insert_index+'][id_groupe]" value="<?php echo($_REQUEST['id_groupe']); ?>" />';
            
            insert_index++;
            content += '</td>';
            content += '<td><a href="javascript:;" class="delete_link"><?php echo(_T('ecatalogue:delete')); ?></a></td>';
            content += '</tr>';
           container.append(content);
	   });
       
       $('.list_form .delete_link').live('click', function(){
            if (confirm('<?php echo(_T('ecatalogue:delete_element')); ?> "' + $(this).parent().prev().find('input').val() + '"?')) {                
                var element_id = $(this).attr('data-element-id');
                if (element_id!=undefined) {                                     
                    $('.list_form').append('<input type="hidden" name="elements_delete['+element_id+']" value="'+element_id+'" />');    
                }
                $(this).parent().parent().remove();    
            }                
       });
       
       $('.list_form select#id_groupe').change(function(){
           <?php //Если делать так, то оно строит путь от этого файла: //echo(generer_url_ecrire('ecatalogue_options')); ?>           
           window.location.replace('<?php echo $GLOBALS['meta']['adresse_site']; ?>/ecrire/?exec=ecatalogue_options&id_groupe='+$(this).find('option:selected').val());           
       });
       
       $('.reponse_formulaire').delay(3000).fadeOut();
    });